<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/connopen.asp"-->
<!--#include file="lib/asp-common-lib.asp"-->
<%
dim dOfferField
Set dOfferField=Server.CreateObject("Scripting.Dictionary")
dOfferField.add "offer_date","领用日期"
dOfferField.add "empe_name","员工"
dOfferField.add "dept_name","部门"
dOfferField.add "class_name","分类"
dOfferField.add "goods_name","文具名"
dOfferField.add "brand_name","品牌"
dOfferField.add "goods_model","型号"
dOfferField.add "unit_name","单位"
dOfferField.add "offer_quantity","数量"
dOfferField.add "goods_unitprice","单价"
dOfferField.add "offer_price","金额"
dOfferField.add "fullname","经手人"
dOfferField.add "offer_memo","备注"

function InsertXLS(xls_name,xls_title)
	sql="insert into xls(xls_name,xls_date,xls_type,xls_title) values('"&xls_name&"','"&date()&"',3,'"&xls_title&"')"
	InsertXLS=ExecuteCommand(sql,true)
end function

function CreateXLS(xls_title,sql)
  dim filepath,fs,myfile,x,link
  Set fs = server.CreateObject("scripting.filesystemobject")
  '--假设你想让生成的EXCEL文件做如下的存放
  filename = "xls/"&xls_title&"_"&FormatTime(now(),"{Y}-{m}-{d}_{h}-{n}-{s}")&".xls"           '指定Excel文件名。
  filepath = Server.MapPath("./"&filename)         '生成Excel文件名及路径。
  '--如果原来的EXCEL文件存在的话删除它
  if fs.FileExists(filepath) then fs.DeleteFile(filepath)        '删除已经存在的同名文件。
  '--创建EXCEL文件
  set myfile = fs.CreateTextFile(filepath,true)
  Set rs = Server.CreateObject("ADODB.Recordset")
  '--从数据库中把你想放到EXCEL中的数据查出来
  rs.Open sql,conn,1,1
  if not rs.EOF then
  
'######################开始写入###################
		dim strLine,responsestr
		strLine=""
		myfile.writeline xls_title'此处可定义Excel标题
		For each x in rs.fields
			strLine= strLine & dOfferField(x.name) & chr(9)  'chr(9)是指的水平方向上的制表符。
		Next

		'--将表的列名先写入EXCEL
		myfile.writeline strLine

		Do while Not rs.EOF
			strLine=""
			for each x in rs.Fields
				strLine= strLine & x.value & chr(9)
			next
			'--将表的数据写入EXCEL
			myfile.writeline strLine
			rs.MoveNext
		loop
  end if
	rs.Close
	set rs = nothing
	set myfile = nothing
	Set fs=Nothing
	CreateXLS=filename
end function



ksrq=trim(SafeRequest("ksrq",0))
if ksrq<>"" then ksrq=cdate(ksrq)
jsrq=trim(SafeRequest("jsrq",0))
if jsrq<>"" then jsrq=cdate(jsrq)
report_title=trim(SafeRequest("report_title",0))
sql="select offer_date,empe_name,dept_name,class_name,goods_name,brand_name,goods_model,unit_name,offer_quantity,goods_unitprice,offer_price,fullname,offer_memo  from offer_goods where offer_bill=false and (offer_date>=#"&ksrq&"# and offer_date<=#"&jsrq&"#) order by offer_date"
xls_name=CreateXLS(report_title,sql)
offer_xls=InsertXLS(xls_name,report_title)
sql="update offer set offer_bill=true,offer_xls="&offer_xls&" where offer_bill=false and (offer_date>=#"&ksrq&"# and offer_date<=#"&jsrq&"#)"
call ExecuteCommand(sql,false)

set dOfferField=nothing
%>

<!--#include file="lib/connclose.asp"-->

